package com.sk.ccflower.lib.commonUtils;


import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;

import org.apache.log4j.Logger;

public class ZipUtil{

	private Logger log;

	private String zipFileName;

	private String[] files;

	public ZipUtil(){
		this.log=Logger.getLogger( getClass() );
	}

	public void setZipFileName( String zipFileName ){
		this.zipFileName=zipFileName;
	}

	public void setFiles( String[] files ){
		this.files=files;
	}

	public void makeZip(){
		byte[] buff=new byte[2048];

		ZipOutputStream zos=null;
		FileInputStream fis=null;
		int len=0;

		try{
			zos=new ZipOutputStream( new FileOutputStream( this.zipFileName ) );
			for( int i=0; i<this.files.length; i++ ){
				fis=new FileInputStream( this.files[i] );
				zos.putNextEntry( new ZipEntry( this.files[i] ) );

				while( ( len=fis.read( buff ) )>0 ){
					zos.write( buff , 0 , len );
				}
				zos.closeEntry();
				fis.close();
			}
			this.log.debug( "#MAKE ZIP SUCCESS = "+this.zipFileName );
		} catch( Exception ex ){
			this.log.error( ex.toString() , ex );
		} finally{
			if( zos!=null ){
				try{
					zos.close();
				} catch( IOException ex1 ){
				}
			}
		}

	}

	public void unZip( boolean rootFoler ){

	}

}
